package ishaportalserver.apps.admin;

import ishaportalserver.apps.Utils;
import ishaportalserver.shared.apps.admin.UserProp;
import ishaportalserver.shared.rest.PutResponse;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

@Path("/user/")
public class UserAPI {
	
	@GET
	@Path("/list/")
	public String list(@QueryParam("callback") String callback) {
		
		Repository repository = new Repository();
		List<UserProp> allProps = repository.getAllUsers();

		String json = Utils.toJson(allProps, callback);
		return json;
	}
	
	@PUT
	@Path("/add/")
	public String add(@QueryParam("email") String email, 
			@QueryParam("callback") String callback) {
		
		Repository repository = new Repository();
		PutResponse prop = repository.addUser(email);
		
		String json = Utils.toJson(prop, callback);
		return json;						
	}
	
	@PUT
	@Path("/update/")
	public String update(@QueryParam("id") long id, 
			@QueryParam("newemail") String newEmail, @QueryParam("callback") String callback) {
		
		Repository repository = new Repository();
		PutResponse prop = repository.updateUser(id, newEmail);
		
		String json = Utils.toJson(prop, callback);
		return json;						
	}

}
